﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar;
using DevComponents.Editors.DateTimeAdv;
using QLTB.Controllers;
using QuanLyThietBi.Manager;
using QuanLyThietBi.ManagerBase;
using QuanLyThietBi.HamXuLy;
using QuanLyThietBi.Entity;


namespace QLTB.Forms
{
    public partial class FrmLoaiThietBi : DevComponents.DotNetBar.Office2007Form
    {
        
        #region Fields
       
        FrmEditLoaiThietBi m_FrmEditLoaiThietBi = null;
             
        #endregion

        public FrmLoaiThietBi()
        {
            InitializeComponent();
        }

        private void FrmLoaiThietBi_Load(object sender, EventArgs e)
        {
            LoadFrom();
        }

        private void LoadFrom()
        {
            DataTable dtLoaiTB = TBL_LoaiThietBiManager.CreateInstant().LayDanhSachLoaiThietBi();
            if (dtLoaiTB.Rows.Count >= 0)
            {
                HamXuLy tblLoaiTB = new HamXuLy();
                tblLoaiTB.LoadData(dgvLoaiThietBi, bnLoaiThietBi, dtLoaiTB);
            }
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            HamXuLy GetID = new HamXuLy();
            string sMaLoaiTB = GetID.LayMaID("P_GetMaLoaiTB");
            m_FrmEditLoaiThietBi = new FrmEditLoaiThietBi(sMaLoaiTB);
            m_FrmEditLoaiThietBi.ThemEvent += new EventHandler(Them_Event);
            m_FrmEditLoaiThietBi.Text = "Thêm mới Loại thiết bị kỹ thuật";
            m_FrmEditLoaiThietBi.Show();
        }
        private void Them_Event(object sender, EventArgs e)
        {
            LoadFrom();
        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            if (MessageBoxEx.Show("Bạn có chắc chắn xóa dòng này không?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dgvLoaiThietBi.SelectedRows)
                {
                    
                    TBL_LoaiThietBiManager.CreateInstant().DeleteByMaLoaiTB(row.Cells[1].Value.ToString());
                }
            }
            LoadFrom();

        }

        private void bindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection dtselect = dgvLoaiThietBi.SelectedCells;
            m_FrmEditLoaiThietBi = new FrmEditLoaiThietBi(dtselect[1].Value.ToString());
            m_FrmEditLoaiThietBi.ThemEvent += new EventHandler(Them_Event);
            m_FrmEditLoaiThietBi.Text = "Hiệu chỉnh thông tin loại thiết bị kỹ thuật";
            m_FrmEditLoaiThietBi.Show();
        }

       
        private void btnthemoi_Click(object sender, EventArgs e)
        {
          
        }

        private void btnsuathongtin_Click(object sender, EventArgs e)
        {
           
        }

        private void btnlammoi_Click(object sender, EventArgs e)
        {
            
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            
        }

        private void dgvLoaiThietBi_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewSelectedCellCollection dtselect = dgvLoaiThietBi.SelectedCells;
            m_FrmEditLoaiThietBi = new FrmEditLoaiThietBi(dtselect[1].Value.ToString());
            m_FrmEditLoaiThietBi.ThemEvent += new EventHandler(Them_Event);
            m_FrmEditLoaiThietBi.Text = "Hiệu chỉnh thông tin loại thiết bị kỹ thuật";
            m_FrmEditLoaiThietBi.Show();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
           
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
          
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            
        }

        private void btnrefreshf_Click(object sender, EventArgs e)
        {
            //LoadFrom();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bindingNavigatorExitItem_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnrefresh_Click(object sender, EventArgs e)
        {
            LoadFrom();
        }

        private void buttonItem2_Click(object sender, EventArgs e)
        {
            HamXuLy GetID = new HamXuLy();
            string sMaLoaiTB = GetID.LayMaID("P_GetMaLoaiTB");
            m_FrmEditLoaiThietBi = new FrmEditLoaiThietBi(sMaLoaiTB);
            m_FrmEditLoaiThietBi.ThemEvent += new EventHandler(Them_Event);
            m_FrmEditLoaiThietBi.Text = "Thêm mới Loại thiết bị kỹ thuật";
            m_FrmEditLoaiThietBi.Show();
        }

        private void buttonItem3_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedCellCollection dtselect = dgvLoaiThietBi.SelectedCells;
            m_FrmEditLoaiThietBi = new FrmEditLoaiThietBi(dtselect[1].Value.ToString());
            m_FrmEditLoaiThietBi.ThemEvent += new EventHandler(Them_Event);
            m_FrmEditLoaiThietBi.Text = "Hiệu chỉnh thông tin loại thiết bị kỹ thuật";
            m_FrmEditLoaiThietBi.Show();
        }

        private void buttonItem4_Click(object sender, EventArgs e)
        {
            if (MessageBoxEx.Show("Bạn có chắc chắn xóa dòng này không?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dgvLoaiThietBi.SelectedRows)
                {
                    TBL_LoaiThietBiManager.CreateInstant().DeleteByMaLoaiTB(row.Cells[1].Value.ToString());
                }
            }
            LoadFrom();
        }

        private void buttonItem5_Click(object sender, EventArgs e)
        {
            LoadFrom();
        }

        private void buttonItem6_Click(object sender, EventArgs e)
        {
            this.Close();
        }

          }
}